/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.una.accidentmanagement.view;

import br.com.una.accidentmanagement.bo.TicketController;
import br.com.una.accidentmanagement.model.Ticket;
import br.com.una.accidentmanagement.view.manipulator.TicketTable;
import java.util.List;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.PlainDocument;
import javax.swing.text.Segment;

/**
 *
 * @author santosmgbh
 */
public class FilterDocument extends PlainDocument{
    
    private StringBuilder texto = new StringBuilder();
    private TicketController ticketController = new TicketController();
    private String fieldFilter;
    private TicketTable ticketTable;

    public FilterDocument(TicketTable listToFilter) {
        this.ticketTable = listToFilter;
    }        

    public void setFieldFilter(String fieldFilter) {
        this.fieldFilter = fieldFilter;
    }
    
    
    
    @Override
    public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
        super.insertString(offs, str, a); 
        texto.append(str);
        ticketTable.putAllDate(ticketController.getTicketByField(fieldFilter, texto.toString()));        
        ticketTable.refresh();        
    }

    @Override
    public void remove(int offs, int len) throws BadLocationException {
        super.remove(offs, len);
        texto.deleteCharAt(texto.length()-1); //To change body of generated methods, choose Tools | Templates.
        System.out.println(texto.toString());
        ticketTable.putAllDate(ticketController.getTicketByField(fieldFilter, texto.toString()));        
        ticketTable.refresh();
    }

    
    
    
    
    
    
    

    
}
